home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
answrbok
/
6_10.lha
/
6_10
/
6_10min.c
< prev
next >
Wrap
Text File
|
1993-08-08
|
725b
|
49 lines
* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
* The C++ Answer Book */
* Tony Hansen */
* All rights reserved. */
*
Subtract u[1..n] - v[1..n] to form w[0..n]
The Art of Computer Programming, volume 2
D. Knuth, Section 4.3.1, Algorithm S
/
include <lint.h>
INT operator-(LINT u, LINT v)
LINT w;
/*
S1 [Initialize]
set j <- n
k <- 0
*/
for (int j = 3, k = 0; ; )
{
/*
S2(a) [Subtract digits]
set w[j] <- (u[j] - v[j] + k) mod b
*/
LINT_Ltype t = u.s[j];
t -= v.s[j];
t -= k;
w.s[j] = t; // % LINT_base
/*
S3 [Loop on j]
decrease j by one
*/
if (--j < 0)
break;
/*
S2(b)
k <- (u[j] - v[j] + k) / b
*/
k = (t / LINT_base) ? 1 : 0;
}
return w;